﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using MosCraft.Utilities.FileIO;

namespace MosCraft.Utilities
{
    public class Settings
    {
        public static XMLSettingsHandler Config;
        private static string fileLocation;

        public Settings()
        {
        }

        public static void initialize(string settingFileLocation)
        {
            Config = new XMLSettingsHandler();
            fileLocation = settingFileLocation;

            if (!Directory.Exists(settingFileLocation))
            {
                Directory.CreateDirectory(settingFileLocation);
            }

            if (File.Exists(fileLocation + @"\settings.xml"))
            {
                Config.Load(fileLocation + @"\settings.xml");
            }
            else
            {
                Config["Controls"].Add(new Node { Name = "MoveForward", Value = "W" });
                Config["Controls"].Add(new Node { Name = "MoveBack", Value = "S" });
                Config["Controls"].Add(new Node { Name = "StrafeRight", Value = "A" });
                Config["Controls"].Add(new Node { Name = "StrafeLeft", Value = "D" });
                Config["Controls"].Add(new Node { Name = "Reach", Value = 4.0D });
                Config["Controls"].Add(new Node { Name = "ShowDebug", Value = true });

                Config["Display"].Add(new Node { Name = "FullScreen", Value = true });
                Config["Display"].Add(new Node { Name = "RenderRange", Value = 240 });
                Config["Display"].Add(new Node { Name = "FOV", Value = 65 });

                Config["Graphics"].Add(new Node { Name = "DisableShaders", Value = false });
                Config["Graphics"].Add(new Node { Name = "useFBO", Value = true });

                Config["Stats"].Add(new Node { Name = "FirstRun", Value = false });
                Config["Stats"].Add(new Node { Name = "CollectData", Value = false });

                Config.Save(fileLocation + @"\settings.xml");
            } 
        }

        public static void save()
        {
            Config.Save(fileLocation + @"\settings.xml");
        }
    }
}
